package com.lpy.book.dao;

import com.lpy.book.model.Book;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;

import java.sql.SQLException;

public class BookDao {
    public static int add(Connection con, Book book) throws SQLException {
        String str = "insert into book (book_name,type_id,author,publish,price,number,status,remark) values(?,?,?,?,?,?,?,?)";

        PreparedStatement pstmt = (PreparedStatement) con.prepareStatement(str);
        pstmt.setString(1, book.getBookName());
        pstmt.setInt(2, book.getBookTypeId());
        pstmt.setString(3, book.getAuthor());
        pstmt.setString(4, book.getPublish());
        pstmt.setDouble(5, book.getPrice());
        pstmt.setInt(6, book.getNumber());
        pstmt.setInt(7, book.getStatus());
        pstmt.setString(8, book.getRemark());
        return pstmt.executeUpdate();
    }

    public static int update(java.sql.Connection con, Book book) throws SQLException {
        //图书信息修改

        String sql = "update book set book_name=?,type_id=?,author=?,publish=?,price=?,number=?,status=?,remark=? where id=?";

        PreparedStatement pstmt = (PreparedStatement) con.prepareStatement(sql);

        pstmt.setString(1, book.getBookName());
        pstmt.setInt(2, book.getBookTypeId());
        pstmt.setString(3, book.getAuthor());
        pstmt.setString(4, book.getPublish());
        pstmt.setDouble(5, book.getPrice());
        pstmt.setInt(6, book.getNumber());
        pstmt.setInt(7, book.getStatus());
        pstmt.setString(8, book.getRemark());
        pstmt.setInt(9, book.getBookId());
        return pstmt.executeUpdate();
    }



}

